/**
 * @Title: LeaveOutAdapter.java
 * @Package: com.jason.bluetooth.fingerprint.adapter
 * @Descripton: TODO
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2014年11月9日23:32:04
 * @Version: V1.0
 */
package com.jason.platform.supervision.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.hzlj.supervision.changsha.R;
import com.jason.platform.supervision.activity.RosterActivity;
import com.jason.platform.supervision.beans.RecordBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: RecordAdapter
 * @Description: 电子档案适配器
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2015-8-8 09:14:30
 */
public class RecordAdapter extends BaseAdapter {

    private static final String TAG = RecordAdapter.class.getSimpleName();

    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private List<RecordBean> mDatas = new ArrayList<RecordBean>();

    public RecordAdapter(Context context) {
        super();
        this.mContext = context;
        this.mLayoutInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.mDatas = new ArrayList<RecordBean>();
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void addAll(List<RecordBean> datas) {
        this.mDatas = datas;
        if (mDatas == null) {
            mDatas = new ArrayList<RecordBean>();
        }
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(
                    R.layout.adapter_record, null);
            holder = new Holder();
            holder.mNameTextView = (TextView) convertView
                    .findViewById(R.id.record_name);
            holder.mPhoneTextView = (TextView) convertView
                    .findViewById(R.id.record_phone);
            holder.mOrganTextView = (TextView) convertView
                    .findViewById(R.id.record_organ);
            holder.mViewTextView = (TextView) convertView
                    .findViewById(R.id.record_view);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        final RecordBean recordBean = (RecordBean) getItem(position);
        if (recordBean != null) {
            holder.mNameTextView.setText(recordBean.getName());
            holder.mPhoneTextView.setText(recordBean.getTelephone());
            holder.mOrganTextView.setText(recordBean.getOrgan());
            holder.mViewTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, RosterActivity.class);
                    intent.putExtra(RosterActivity.KEY_ROSTER_INFO, recordBean);
                    mContext.startActivity(intent);
                }
            });
        }

        //TODO 填充数据
        return convertView;
    }

    class Holder {
        TextView mNameTextView;
        TextView mPhoneTextView;
        TextView mOrganTextView;
        TextView mViewTextView;
    }

}
